public class Daily_Score_Formula {
	double CarbohydratesScore, ProteinScore, FatScore, SodiumScore, TotalScore; //score
	double CarbohydratesNeed, ProteinNeed, FatNeed, SodiumNeed; // nutrition need
	double CarbohydratesConsumption, ProteinConsumption, FatConsumption, SodiumConsumption; // nutrition consumption
	
	Daily_Score_Formula(nutrition_need user, double GivenCarbohydratesConsumption, double GivenProteinConsumption,double GivenFatConsumption, double GivenSodiumCosumption)
	{
		CarbohydratesNeed = user.getCarbohydratesNeed();
		ProteinNeed = user.getProteinNeed();
		FatNeed = user.getFatNeed();
		SodiumNeed = user.getSodiumNeed();
		CarbohydratesConsumption = GivenCarbohydratesConsumption;
		ProteinConsumption = GivenProteinConsumption;
		FatConsumption = GivenProteinConsumption;
		SodiumConsumption = GivenSodiumCosumption;
		CalculatePartialScore();
		setTotalScore();
	}
	
	double max(double a, double b)
	{
		if (a>b)
			return a;
		else
			return b;
	}
	
	private void setCarbohydratesScore(){
		if (CarbohydratesConsumption <= CarbohydratesNeed)
			CarbohydratesScore = 65 * CarbohydratesConsumption / CarbohydratesNeed;
		else
			CarbohydratesScore = max(0, 65 - (CarbohydratesConsumption - CarbohydratesNeed)/5); 
	}
	
	public double getCarbohydratesScore(){
		return CarbohydratesScore;
	}
	
	private void setProteinScore(){
		if (ProteinConsumption <= ProteinNeed)
			ProteinScore = 15 * ProteinConsumption / ProteinNeed;
		else
			ProteinScore = max(0, 15 - (ProteinConsumption - ProteinNeed)/1.25); 
	}
	
	public double getProteinScore(){
		return ProteinScore;
	}
	
	private void setFatScore(){
		if (FatConsumption <= FatNeed)
			FatScore = 10 * FatConsumption / FatNeed;
		else
			FatScore = max(0, 10 - (FatConsumption - FatNeed)); 
	}
	
	public double getFatScore(){
		return FatScore;
	}
	
	private void setSodiumScore(){
		if (SodiumConsumption <= SodiumNeed)
			SodiumScore = 10 * SodiumConsumption / SodiumNeed;
		else
			SodiumScore = max(0, 10 - 2 * (SodiumConsumption - SodiumNeed)); 
	}
	
	public double getSodiumScore(){
		return SodiumScore;
	}
	
	private void CalculatePartialScore()
	{
		setCarbohydratesScore();
		setProteinScore();
		setFatScore();
		setSodiumScore();
	}
	
	private void setTotalScore()
	{
		TotalScore = (double)Math.round((CarbohydratesScore + ProteinScore + FatScore + SodiumScore) * 10) /10.0; // round to 1 decimal place
	}
	
	public double getTotalScore(){
		return TotalScore;
	}
}
